package com.pb.poem.servlet;

import java.io.IOException;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.pb.poem.dao.PoemDao;
import com.pb.poem.dao.impl.PoemDaoImpl;
import com.pb.poem.entity.Poem;
import com.pb.poem.service.impl.PoemServiceImpl;

public class UpdatePoem extends HttpServlet {
	private static final long serialVersionUID = 1L;
   
    public UpdatePoem() {
        super();
        // TODO Auto-generated constructor stub
    }

	@Override
	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		// TODO Auto-generated method stub
	}

	@Override
	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		PoemServiceImpl poemService=new PoemServiceImpl();
		PoemDao poemDao=new PoemDaoImpl();
		poemService.setPoemDao(poemDao);
		
request.setCharacterEncoding("utf-8");
int id=Integer.parseInt(request.getParameter("id"));
String poemname=request.getParameter("poemname");
String author=request.getParameter("author");
String content=request.getParameter("content");
Poem poem=new Poem();
poem.setId(id);
poem.setPoemname(poemname);
poem.setAuthor(author);
poem.setContent(content);

boolean flag=poemService.updatepoem(poem);
if(flag){
response.sendRedirect("admin/showoneself.jsp");
   }
  }
}
